import dayjs from 'dayjs';

//递归菜单


export  function deepTree(list) {
    const result = []
    const map = {}
    //变量数组追加到map中
    for (let item of list) {
        map[item.id]  = {...item}
    }
   
    //再次变历数组
    for ( let item of list) {
      if(!item.parentId){
        result.push(map[item.id]) ;
      }else{
        if(map[item.parentId].children){
          map[item.parentId].children.push(map[item.id]) 
        }else{
          map[item.parentId].children = [map[item.id]] 
        }
      }
    }
    return result
    


  } 

  export function isLeaf(list, id) {
    return list.every((item) => item.parentId !== id);
  }


  export function dateFormat(date, format = "YYYY-MM-DD") {
    return dayjs(date).format(format)
  }